package jqgridjavawrapper;

/**
 * @author Isuru Madushanka Weerarathna
 * @contact uisurumadushanka89@gmail.com
 */
public class JQGridColumnEditRules implements JQPropertyMaker {

    private boolean editHidden = true;
    private boolean searchHidden = false;
    private boolean canNotBeEmpty = true;
    private boolean shoudNumeric = false;
    private boolean shouldInteger = false;
    private boolean shouldEMail = false;
    private boolean shouldURL = false;
    private boolean shouldDate = false;
    private boolean shouldTime = false;

    private boolean customEditUse = false;
    private String customFunction = null;

    public String getCustomFunction() {
        return customFunction;
    }

    public boolean isCanNotBeEmpty() {
        return canNotBeEmpty;
    }

    public boolean isCustomEditUse() {
        return customEditUse;
    }

    public boolean isEditHidden() {
        return editHidden;
    }

    public boolean isSearchHidden() {
        return searchHidden;
    }

    public boolean isShoudNumeric() {
        return shoudNumeric;
    }

    public boolean isShouldDate() {
        return shouldDate;
    }

    public boolean isShouldEMail() {
        return shouldEMail;
    }

    public boolean isShouldInteger() {
        return shouldInteger;
    }

    public boolean isShouldTime() {
        return shouldTime;
    }

    public boolean isShouldURL() {
        return shouldURL;
    }

    public void setShouldURL(boolean shouldURL) {
        this.shouldURL = shouldURL;
    }

    public void setShouldTime(boolean shouldTime) {
        this.shouldTime = shouldTime;
    }

    public void setShouldInteger(boolean shouldInteger) {
        this.shouldInteger = shouldInteger;
    }

    public void setShouldEMail(boolean shouldEMail) {
        this.shouldEMail = shouldEMail;
    }

    public void setShouldDate(boolean shouldDate) {
        this.shouldDate = shouldDate;
    }

    public void setShoudNumeric(boolean shoudNumeric) {
        this.shoudNumeric = shoudNumeric;
    }

    public void setSearchHidden(boolean searchHidden) {
        this.searchHidden = searchHidden;
    }

    public void setEditHidden(boolean editHidden) {
        this.editHidden = editHidden;
    }

    public void setCustomFunction(String customFunction) {
        this.customFunction = customFunction;
    }

    public void setCustomEditUse(boolean customEditUse) {
        this.customEditUse = customEditUse;
    }

    public void setCanNotBeEmpty(boolean canNotBeEmpty) {
        this.canNotBeEmpty = canNotBeEmpty;
    }

    public StringBuilder generateProperties() {
        StringBuilder sb = new StringBuilder();

        sb.append("{");
        sb.append(" edithidden: ").append(getStrRepBool(this.editHidden));
        sb.append(" searchhidden: ").append(getStrRepBool(this.searchHidden));
        sb.append(" required: ").append(getStrRepBool(this.canNotBeEmpty));
        if (this.shoudNumeric)
            sb.append(" number: ").append(getStrRepBool(this.shoudNumeric));
        if (this.shouldInteger)
            sb.append(" integer: ").append(getStrRepBool(this.shouldInteger));
        if (this.shouldEMail)
            sb.append(" email: ").append(getStrRepBool(this.shouldEMail));
        if (this.shouldURL)
            sb.append(" url: ").append(getStrRepBool(this.shouldURL));
        if (this.shouldDate)
            sb.append(" date: ").append(getStrRepBool(this.shouldDate));
        if (this.shouldTime)
            sb.append(" time: ").append(getStrRepBool(this.shouldTime));


        if (this.customEditUse) {
            sb.append(" custom: ").append(getStrRepBool(this.customEditUse));
            if (this.customFunction != null)
                sb.append(" custom_func: ").append(this.customFunction);
        }

        sb.append("}");

        return sb;
    }

    private String getStrRepBool(boolean value){
        return (value ? "true" : "false");
    }

}

